import numpy as np

class SquaredError():
    '''均方误差'''
    @staticmethod
    def fn(y_hat, y):
        '''
        y_hat : numpy array of shape (n, m)
            Predictions for the `n` examples in the batch.
        y : numpy array of shape (n, m)
            Ground truth values for each of `n` examples.
        '''
        return 0.5 * np.linalg.norm(y_hat - y) ** 2
        #return 0.5 * np.sum((y - y_hat) ** 2)

    @staticmethod
    def grad(y_hat, y):
        '''
        y : numpy array of shape (n, m)
            Ground truth values for each of `n` examples.
        y_pred : numpy array of shape (n, m)
            Predictions for the `n` examples in the batch.
        '''
        return y_hat - y


#class CrossEntropy():